
package com.joysuch.wwyt.bp.repository;

import java.util.List;

import com.joysuch.wwyt.bp.entity.inspect.BpAppPlanTask;
import com.joysuch.wwyt.bp.entity.inspect.BpInspectPlan;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;

public interface BpInspectPlanRepository
        extends JpaRepository<BpInspectPlan, Long>, JpaSpecificationExecutor<BpAppPlanTask>, QuerydslPredicateExecutor<BpInspectPlan> {
    
    int countByInspectTypeId(Long inspectTypeId);

    BpInspectPlan findByName(String name);

    @Query("select name from BpInspectPlan where id=:id")
    String findNameById(Long id);

    int countByName(String name);

    List<BpInspectPlan> findByInitiateStatus(String initiateStatus);

    @Query(value = "select id from BpInspectPlan where name like %?1%")
    List<Long> findIdByNameLike(String name);

    @Query(value = "select t.name from BpInspectPlan m, BpInspectType t where m.inspectTypeId=t.id and m.id = ?1")
    String findInspectTypeNameById(Long inspectPlanId);

}
